<template>
	<view class="indexs">
		<view class="header header_wi" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style=" 'height:' + gaodu + 'px;line-height:' + gaodu +
          'px;top:' +
          gaodutops +
          'px;'
        ">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo">
						<image :src="imgUrl + '/dzx_img33.png'" mode="widthFix"></image>
					</view>
					<view class="index_wenben">{{
            $t("page_my_bangdingemil.bind_mailbox")
          }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;padding-bottom:130rpx;'">
			<!--未绑定邮箱 <view class="my_bangdingemil_show">
      <view class="my_bangdingemil_center">
        <view class="my_bangdingemil_list">
          <view class="my_bangdingemil_cont">
            <view class="my_bangdingemil_cont_l">
              <image src="../../images/dzx_img145.png'"></image>
              <text>邮箱</text>
            </view>
            <view class="my_bangdingemil_cont_r">
              <input type="text" placeholder="请输入邮箱" />
            </view>
          </view>
          <view class="my_bangdingemil_cont" style="padding: 23rpx 0;">
            <view class="my_bangdingemil_cont_l">
              <image src="../../images/dzx_img146.png'"></image>
              <text>验证码</text>
            </view>
            <view class="my_bangdingemil_cont_r">
              <input type="text" placeholder="请输入验证码" style="width: 50%;" />
              <view class="my_bangdingemil_cont_r1">获取验证码</view>
            </view>
          </view>
        </view>
      </view>
      <view class="baoguo_btns">
        <view class="baoguo_btns_posi">
          <view class="baoguo_btn">确认绑定</view>
        </view>
      </view>
    </view> -->
			<!--绑定了邮箱
			 <view class="my_bangdingemil_isshow">
      <view class="my_bangdingemil_you">
        <image src="../../images/dzx_img147.png'"></image>
        <view class="my_bangdingemil_yout1">已绑定邮箱</view>
        <view class="my_bangdingemil_yout2">3535443@qq.com</view>
      </view>
      <view class="my_bangdingemil_btnss">
        <view class="my_bangdingemil_btns">
          <view class="my_bangdingemil_btn1">解除绑定</view>
          <view class="my_bangdingemil_btn2">更改邮箱</view>
        </view>
      </view>
    </view> -->

			<view class="my_bangdingemil_show">
				<view class="my_bangdingemil_center">
					<view class="my_bangdingemil_list">
						<view class="my_bangdingemil_cont">
							<view class="my_bangdingemil_cont_l">
								<image :src="imgUrl + '/dzx_img145.png'"></image>
								<text>{{ $t("page_my_bangdingemil.mailbox") }}</text>
							</view>
							<view class="my_bangdingemil_cont_r">
								<input disabled="true" type="text" :placeholder="$t('page_my_bangdingemil.p_i_mailbox')"
									:value="
                    email.email != 0
                      ? email.email
                      : $t('page_my_bangdingemil.unbound')
                  " />
							</view>
						</view>
						<view class="my_bangdingemil_cont">
							<view class="my_bangdingemil_cont_l">
								<image :src="imgUrl + '/dzx_img145.png'"></image>
								<text>{{ $t("page_my_bangdingemil.new_mailbox") }}</text>
							</view>
							<view class="my_bangdingemil_cont_r"><input type="text"
									:placeholder="$t('page_my_bangdingemil.p_i_mailbox')" @input="emailFun" /></view>
						</view>
						<view class="my_bangdingemil_cont" style="padding: 23rpx 0">
							<view class="my_bangdingemil_cont_l">
								<image :src="imgUrl + '/dzx_img146.png'"></image>
								<text>{{ $t("page_my_bangdingemil.code") }}</text>
							</view>
							<view class="my_bangdingemil_cont_r">
								<input @input="codeFun" type="text" :placeholder="$t('page_my_bangdingemil.p_code')"
									style="width: 50%" />
								<view class="my_bangdingemil_cont_r1" @click="getUpdateEmail">{{
                  $t("page_my_bangdingemil.g_code")
                }}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="baoguo_btns">
					<view class="baoguo_btns_posi">
						<view @click="UpdateMail" class="baoguo_btn">{{
              $t("page_my_bangdingemil.Confirm_changes")
            }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let request = require("../../../utils/require");
	// pages/shouye/shouye_zkc/shouye_zkc.js
	const app = getApp();
	export default {
		data() {
			return {
				navH: app.globalData.navHeight,
				gaodu: app.globalData.height,
				gaodutops: app.globalData.top,
				imgUrl: app.globalData.imgUrl,
				email: "",
				emailval: "",
				code: "",
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad() {
			var that = this;
			that.emailList();
		},
		onShow() {
			var that = this;
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			jumpzuo() {
				uni.navigateBack();
			},
			//邮箱价值
			emailFun(e) {
				this.emailval= e.detail.value
			},
			codeFun(e) {
				this.code= e.detail.value
			},
			//我的邮箱
			emailList(e) {
				var that = this;
				var data = {
					token: uni.getStorageSync("token"),
				};
				request
					.post(
						`index.php?s=/api/user/email&wxapp_id=` +
						uni.getStorageSync("web_id"),
						data
					)
					.then((res) => {
						if (res.data.code == 1) {
							that.email = res.data.data.userInfo
							console.log(res.data.data.userInfo, "res.data.data.list.data?");
						}
					});
			},
			//发送邮箱验证码
			getUpdateEmail() {
				var that = this;
				var token = {
					token: uni.getStorageSync("token"),
					email: that.emailval,
				};

				request
					.get(
						`index.php?s=/api/user/emailCode&wxapp_id=` +
						uni.getStorageSync("web_id"),
						token
					)
					.then((res) => {
						if (res.data.code == 0) {
							uni.showToast({
								title: res.data.msg,
							});
							return false;
						}
					});
			},
			UpdateMail() {
				var that = this;
				var token = {
					token: uni.getStorageSync("token"),
					code: that.code,
				};

				request
					.get(
						`index.php?s=/api/user/UpdateMail&wxapp_id=` +
						uni.getStorageSync("web_id"),
						token
					)
					.then((res) => {
						console.log(res.data, 87654);
						if (res.data.code == 1) {
							that.email = res.data.data.userInfo
						} else {
							uni.showToast({
								title: res.data.msg,
							});
							return false;
						}
					});
			},
		},
	};
</script>
<style>
	@import "./my_bangdingemil.css";
</style>